﻿<%@ Control Language="C#" ClassName="MainMenu" %>
<%@ Register Src="~/Controls/_UI/Telerik/RowContextMenuIncludes/LoanPagesMenu.ascx" TagPrefix="Menu" TagName="LoanPages" %>
<%@ Import Namespace="Dimok" %>
<%@ Import Namespace="Dimok.Web.UI" %>
<%@ Import Namespace="AjaxMasterExtentions" %>
<asp:ScriptManagerProxy runat="server">
	<Scripts>
		<asp:ScriptReference Path="~/JS/UI/MainMenu.js" />
	</Scripts>
</asp:ScriptManagerProxy>
<script runat="server">
	private TableControlAjax TableExtender;
	public HtmlSelect selReport = null;
	
	protected override void OnLoad(EventArgs e) {
		base.OnLoad(e);
		Page.PreRenderComplete+=new EventHandler(Page_PreRenderComplete);
	}
	protected void dsFilters_Selecting(object sender, LinqDataSourceSelectEventArgs e) {
		e.Result = Page.GetProfiler().Grid.Reports.
			Select(s => new { ReportName = s.Key == Profiler.DEFAULT_REPORT_NAME ? "" : s.Key }).
			OrderBy(s => s.ReportName);
	}
	protected void menuFiltersList_PreRender(object sender, EventArgs e) {
		selReport = Find.ControlByID(sender as Control, "selReport") as HtmlSelect;
		((Control)sender).Visible = TableExtender != null;
	}

	void Page_PreRenderComplete(object sender, EventArgs e) {
		selReport.Value = Page.GetProfiler().Report_FindName();
		popupFilter.TargetControlID = selReport.ID;
		JS.RegisterClientScriptBlock(this,
			string.Format("var FirstTableExtender = function(){{return {0};}}\n",
			TableExtender == null ? "null" : "$find('" + TableExtender.Container.ClientID + "')")
			);

	}
	protected void selFontSize_PreRender(object sender, EventArgs e) {
		((HtmlSelect)sender).Value = Page.Master.UserFontSize();
	}
	protected void Menu_PreRender(object sender, EventArgs e) {
		TableExtender = Page.ChildrenByType<TableControlAjax>().Where(d=>(d.DocksID+"")!= "").FirstOrDefault();
		((Control)sender).ScriptLocalFind();
		cmLoanPages.Controls[0].ScriptLocalFind();
	}
	protected void MenuFilters_PreRender(object sender, EventArgs e) {
		((Control)sender).Visible = TableExtender != null;
	}
</script>
<Menu:LoanPages ID="cmLoanPages" runat="server" />
<telerik:RadMenu ID="menuMain" runat="server" Width="99%" Skin="Vista" OnPreRender="Menu_PreRender">
<Items>
	<telerik:RadMenuItem>
		<ItemTemplate>
			<select onchange="loadHtmlCss(this.value)" id="selFontSize" OnPreRender="selFontSize_PreRender" RunAt="server">
			<option value="80%">80</option>
			<option value="90%">90</option>
			<option value="100%" selected="selected">100</option>
			<option value="110%">110</option>
			<option value="120%">120</option>
			<option value="130%">130</option>
			<option value="140%">140</option>
			</select>
		</ItemTemplate>
	</telerik:RadMenuItem>
	<telerik:RadMenuItem Text="Filters" OnPreRender="MenuFilters_PreRender">
			<Items>
				<telerik:RadMenuItem Value="FilterAdd" Text="Save Filter"></telerik:RadMenuItem>
				<telerik:RadMenuItem Value="FilterDelete" Text="Delete Filter"></telerik:RadMenuItem>
			</Items>
	</telerik:RadMenuItem>
	<telerik:RadMenuItem OnPreRender="menuFiltersList_PreRender">
		<ItemTemplate>
			<select id="selReport" onchange="showFilter(this.value)" runat="server" onprerender="ScriptLocalGet"
				DataSourceID="dsFilters" DataTextField="ReportName" datavaluefield="ReportName"></select>	
			<asp:LinqDataSource ID="dsFilters" OnSelecting="dsFilters_Selecting" runat="server" />
		</ItemTemplate>
	</telerik:RadMenuItem>
	<telerik:RadMenuItem Text="UIs">
		<Items>
			<telerik:RadMenuItem Text="Collection Buckets" Value="OpenWindow" NavigateUrl="/Manager/Admin/Users/CollectionBuckets.aspx#" PostBack="false" Target="_blank"></telerik:RadMenuItem>
			<telerik:RadMenuItem Text="Bridge" Value="OpenWindow" NavigateUrl="/Manager/Bridge.aspx#" PostBack="false" Target="_blank"></telerik:RadMenuItem>
			<telerik:RadMenuItem Text="Search" Value="OpenDialog" NavigateUrl="/manager/showrs.aspx?servicePath=/Manager/Menu/Lists.asmx%3F&serviceFunc=ListWhere%28null%29&onFilter=ListWhere&title=Find Applicant#" PostBack="false" Target="_blank"></telerik:RadMenuItem>
			<telerik:RadMenuItem Text="Profiles" Value="OpenWindow" NavigateUrl="/Manager/Admin/ProfilesManager.aspx#" PostBack="false" Target="_blank"></telerik:RadMenuItem>
			<telerik:RadMenuItem Text="Bridge To USIX" Value="OpenWindow" NavigateUrl="/Manager/USIX/USIXBridge.aspx#" PostBack="false" Target="_blank"></telerik:RadMenuItem>
			<telerik:RadMenuItem Text="Users" Value="OpenWindow" NavigateUrl="/Manager/Admin/Users/List.aspx#" PostBack="false" Target="_blank"></telerik:RadMenuItem>
			<telerik:RadMenuItem Text="Payment" runat="server">
				<Items>
					<telerik:RadMenuItem Text="Payments" Value="OpenWindow" NavigateUrl="/Manager/Collection/PaymentsMB.aspx#" PostBack="false" Target="_blank"></telerik:RadMenuItem>
					<telerik:RadMenuItem Text="Settings" Value="OpenWindow" NavigateUrl="/Manager/Settings/Payments/Payments.aspx#" PostBack="false" Target="_blank"></telerik:RadMenuItem>
				</Items>
			</telerik:RadMenuItem>
			<telerik:RadMenuItem Text="Settings">
				<Items>
					<telerik:RadMenuItem Text="Contract Holders" Value="OpenWindow" NavigateUrl="/Manager/Admin/Dealer/ContractHolders.aspx#" PostBack="false" Target="_blank"></telerik:RadMenuItem>
					<telerik:RadMenuItem Text="Decision Engine" Value="OpenWindow" NavigateUrl="/manager/GuideLines/GLRules.aspx#" PostBack="false" Target="_blank"></telerik:RadMenuItem>
				</Items>
			</telerik:RadMenuItem>
		</Items>
	</telerik:RadMenuItem>
	<telerik:RadMenuItem Text="Bay Quest">
		<Items>
			<telerik:RadMenuItem Text="New Batch" Value="OpenWindow" NavigateUrl="/Manager/BayQuest/NewPurchase.aspx#" PostBack="false" Target="_blank"></telerik:RadMenuItem>
			<telerik:RadMenuItem Text="Rules" Value="OpenWindow" NavigateUrl="/Manager/GuideLines/GLRules.aspx?BankID=22#" PostBack="false" Target="_blank"></telerik:RadMenuItem>
		</Items>
	</telerik:RadMenuItem>
	<telerik:RadMenuItem Text="Status">
		<Items>
			<telerik:RadMenuItem Text="Buy Back">
				<Items>
					<telerik:RadMenuItem>
						<ItemTemplate>
							<select><option>Review</option><option>Send To Dealer</option><option>Money Received</option></select>
						</ItemTemplate>
					</telerik:RadMenuItem>
				</Items>
			</telerik:RadMenuItem>
			<telerik:RadMenuItem Text="Collection">
				<Items>
					<telerik:RadMenuItem>
						<ItemTemplate>
							<select><option>Repo Review</option><option>Repo Approved</option><option>Back To Collect</option></select>
						</ItemTemplate>
					</telerik:RadMenuItem>
				</Items>
			</telerik:RadMenuItem>
			<telerik:RadMenuItem Text="Repossession">
				<Items>
					<telerik:RadMenuItem>
						<ItemTemplate>
							<select><option>Start Repo</option><option>Skip Trace</option><option>Out For Repo</option><option>Pre-Auction</option></select>
						</ItemTemplate>
					</telerik:RadMenuItem>
				</Items>
			</telerik:RadMenuItem>
		</Items>
	</telerik:RadMenuItem>
	<telerik:RadMenuItem Text="Letters">
		<Items>
			<telerik:RadMenuItem Text="Welcome" Value="Welcome" />
			<telerik:RadMenuItem Text="Past Due">
				<Items>
					<telerik:RadMenuItem Text=" 2 to  6"   Value="Delinquency.PastDue_02_06" />
					<telerik:RadMenuItem Text="15 to 20" Value="Delinquency.PastDue_15_20" />
					<telerik:RadMenuItem Text="25 to 29" Value="Delinquency.PastDue_25_29" />
					<telerik:RadMenuItem Text="31 to 35" Value="Delinquency.PastDue_31_35" />
					<telerik:RadMenuItem Text="> 35" Value="Delinquency.PastDue_36" />
					<telerik:RadMenuItem Text="Broken Promise" Value="Delinquency.BrokenPromise" />
					<telerik:RadMenuItem Text="N.S.F." Value="Delinquency.NSF" />
				</Items>
			</telerik:RadMenuItem>
			<telerik:RadMenuItem Text="Re-Start" Value="ReStart" />
			<telerik:RadMenuItem Text="Invoice" Value="Invoice" />
		</Items>
	</telerik:RadMenuItem>
	<telerik:RadMenuItem Text="Reports">
		<Items>
			<telerik:RadMenuItem Text="Collection" PostBack="false" Target="_blank">
				<Items>
					<telerik:RadMenuItem Text="Collection KPI" NavigateUrl="/Reports/Pages/Report.aspx?ItemPath=%2fCollection%2fCollection+Performance" ToolTip="Collection Key Performance Indicators" PostBack="false" Target="_blank" />
					<telerik:RadMenuItem Text="Performance" NavigateUrl="/Reports/Pages/Report.aspx?ItemPath=%2fCollection%2fCollection+Performance" PostBack="false" Target="_blank" />
					<telerik:RadMenuItem Text="Today" NavigateUrl="/Reports/Pages/Report.aspx?ItemPath=%2fCollection%2fCollection+Today" PostBack="false" Target="_blank" />
					<telerik:RadMenuItem Text="Payment DPDs" NavigateUrl="/ReportServer/Pages/ReportViewer.aspx?%2fCollection%2fPayment+DPDs&rs:Command=Render" Target="_blank" PostBack="false" />
				</Items>
			</telerik:RadMenuItem>
			<telerik:RadMenuItem Text="Finance">
				<Items>
					<telerik:RadMenuItem Text="Daily Totals" NavigateUrl="/ReportServer/Pages/ReportViewer.aspx?%2fCommon%2fDaily+Totals&rs:Command=Render" PostBack="false" Target="_blank" />
					<telerik:RadMenuItem Text="DPDs" NavigateUrl="/ReportServer/Pages/ReportViewer.aspx?%2fCommon%2fDays+Past+Due&rs:Command=Render" PostBack="false" Target="_blank" />
				</Items>
			</telerik:RadMenuItem>
		</Items>
	</telerik:RadMenuItem>
</Items>
</telerik:RadMenu>

<asp:Panel ID="pnlFilterPopup" runat="server" style="display:none;z-index:10000" onkeyup="if(event.keyCode == 27)hideFilterPopup()">
<div class="Office2007 VerticalMiddle PopupMenu" style="z-index:10000">
	<span>Filter Name: </span><input id="newFilterName" style="overflow-x:visible;" /><br />
	<input type="button" Value="OK" onclick="addFilter(this)" style="overflow:visible;width:4em" />
	<input type="button" Value="Cancel" onclick="hideFilterPopup()" style="overflow:visible" />
</div>
</asp:Panel>
<asp:Panel ID="pnlFilterMenu" style="display:none" onkeyup="if(event.keyCode == 27)hideFilterMenu()" runat=server>
	<ul style="list-style:none" Class="Office2007 Menu">
		<li onclick="setTimeout(function(){hideFilterMenu();showFilterPopup()},200)"><a HRef="#">New Filter</a></li>
		<li onclick="deleteReport()"><a href="#">Delete Filter</a></li>
	</ul>
</asp:Panel>
<asp:Label id="lblFilters" style="display:none" runat="server"></asp:Label>
<ajaxtk:PopupControlExtender ID="popupFilter" BehaviorID="popupFilterBehavior" TargetControlID="lblFilters" OffsetY="31" Position=Bottom PopupControlID="pnlFilterPopup" runat="server" />
<ajaxtk:HoverMenuExtender ID="menuFilters" BehaviorID="menuFiltersBehavior" PopupPosition="Bottom" TargetControlID="lblFilters" PopupControlID="pnlFilterMenu" HoverDelay="500" PopDelay="1000" runat="server" />
<script src="/Manager/Common/Common.js"></script>
<script>
	var get_docks = function() { return $find("Docks") }
	Sys.Application.add_init(function() {
		var mainMenuObject = $create(Dimok.MainMenu, { id: "MAIN_MENU" }, null, null, null);
		Sys.Application.add_load(function() {
			menuMain().add_itemClicked(menuMain_Handler);
			if (FirstTableExtender()) {
				popupFilter().add_showing(initFilterMenu);
				FirstTableExtender().get_RGE().add_filterChanged(fetchFilter);
			}
		});
		function menuMain_Handler(sender, eventArgs) {
			var element = eventArgs._item.get_element();
			switch (eventArgs._item.get_value()) {
				case "FilterAdd": setTimeout(function() { showFilterPopup() }, 100); break;
				case "FilterDelete": deleteReport(); break;
				case "OpenDialog":
					showModelessDialog(eventArgs.get_item().get_navigateUrl(), { opener: self, onSelect: showApplInfo }, "resizable:1;status:0;help:0");
					break;
				case "OpenWindow":
					mainMenuObject.openWindow(eventArgs.get_item().get_navigateUrl(), eventArgs.get_item().get_text());
					break;
			}
			sender.close();
		}
	});
	var menuFilters = function() { return $find('menuFiltersBehavior') }
	var popupFilter = function() { return $find('popupFilterBehavior') }
	function initFilterMenu(sender, eventArgs) {
		var filterName = selReport().value;
		var jqPanel = $J(sender.get_element());
		jqPanel.find("#newFilterName")[0].value = filterName;
		setTimeout(function() { jqPanel.find("#newFilterName").focus().select(); }, 500);
//		Array.clear(filterAutoComplete);
//		filterAutoComplete.push("DIMOK");
//		filterAutoComplete.push("DIMON");
//		$J("#newFilterName").autocomplete(filterAutoComplete);
		//jqPanel.find("#btnDeleteFilter")[0].value = "Delete [" + filterName + "] filter";
	}
	function hideFilterMenu() { menuFilters()._onUnhover(); }
	function hideFilterPopup() { popupFilter().hidePopup(); }
	function showFilterPopup() { popupFilter().showPopup(); }

	function fetchFilter(sender, eventArgs) {
		var reportName = (eventArgs.get_report() || {}).reportName || "";
		selReport().value = reportName;
	}
	function showFilter(filterName) {
		$J.blockUI({ message: 'Loading Filter ...' });
		FirstTableExtender().get_RGE().showReport(filterName, function() { location.reload(); });
	}
	function addFilter(el) {
		var filterName = $J(el).parent().find("#newFilterName")[0].value;
		FirstTableExtender().get_RGE().saveReport(filterName, _cb);
		function _cb(result) {
			selReport().value = filterName;
			if (selReport().value != filterName) {
				selReport()[selReport().length] = new Option(filterName, filterName);
				selReport().selectedIndex = [selReport().length] - 1;
			}
			hideFilterPopup();
		}
	}
	function deleteReport() {
		var selectedIndex = selReport().selectedIndex;
		FirstTableExtender().get_RGE().deleteReport(selReport().value, _cb);
		function _cb(ev) {
			if (selectedIndex > 0) {
				selReport().options.remove(selectedIndex);
				selReport().selectedIndex = 0;
			} else FirstTableExtender().get_RGE().showFilter(selReport.value);
			hideFilterMenu();
		}
	}
</script>
